package com.eascs.admin.o2o.receivedRecords.service;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.o2o.receivedRecords.dao.ReceivedRecordsDao;
import com.eascs.admin.o2o.receivedRecords.entity.ReceivedRecordsEntity;
import com.eascs.admin.o2o.receivedRecords.entity.ReceivedRecordsVo;
import com.eascs.app.dao.PageResult;
import com.eascs.workflow.common.service.sys.SysPermissionService;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ReceivedRecordsService {
	@Autowired
	ReceivedRecordsDao receivedRecordsDao;
	@Reference
	private SysPermissionService sysPermissionService;
	/**
	 * 分页查询--回款记录
	 */
	public  PageResult<Object[]> getHKJLByPageService(ReceivedRecordsVo vo){
	return receivedRecordsDao.getHKJLByPage(vo);
}
	@Transactional("o2oTransactionManager")//事务管理
	public int insertRecords(ReceivedRecordsEntity receivedEntity) {
		return receivedRecordsDao.insert(receivedEntity);
	}
	/**
	 *回款记录维护模块--查询单据基本信息
	 * @param billCode
	 * @return
	 */
	public ReceivedRecordsVo findReceivedRecordsEntity(String billCode) {
		return receivedRecordsDao.findReceivedRecordsEntity(billCode);
	}

	/**
	 * 通过主键id查找o2o_received_records表中的所有数据
	 * @param id
	 * @return
	 */
	public ReceivedRecordsEntity getHKJLById(String id) {
		StringBuffer querySql = new StringBuffer();
		querySql.append(" select  *  ");
		querySql.append(" from o2o_received_records orr ");
		querySql.append(" where 1=1 ");
		querySql.append(" and orr.id =? ");
		return receivedRecordsDao.findEntity(querySql.toString(), ReceivedRecordsEntity.class, id);
	}
	
	/**
	 * 软删除--删除回款记录
	 * @param entity
	 * @return
	 */
	public boolean deleteHKJL(String id) {
		StringBuffer querySql = new StringBuffer();
		querySql.append("UPDATE o2o_received_records orr SET orr.is_del = 'Y' WHERE orr.id = ?");
		int flag = receivedRecordsDao.execute(querySql.toString(),id);
		return flag > 0 ? true : false;
	}
	/**
	 * 根据id查出billCode
	 * @param id
	 * @return
	 */
	public ReceivedRecordsVo getBillCodeById(String id) {
		StringBuffer querySql = new StringBuffer();
		querySql.append(
				" select  oll.bill_code AS billCode "
				+ " from o2o_loanapply oll, o2o_received_records orr "
				+ " where oll.loanapply_no = orr.loanapply_no "
				+ " and orr.id = ? ");
		return receivedRecordsDao.findEntity(querySql.toString(), ReceivedRecordsVo.class, id);
	}
	
}